//: Playground - noun: a place where people can play

import Cocoa

protocol Food {}

protocol Animal {
    associatedtype F: Food
    func eat(_ food: F)
}

struct Meat: Food {}
struct Grass: Food {}

struct Tiger: Animal {
    
//    typealias F = Meat    //可以省略，被隐式的推断出
    
    internal func eat(_ food: Meat) {
        print("eat \(food)")
    }
    
}

struct Sheep: Animal {
    
    internal func eat(_ food: Grass) {
        
    }
    
}

//let meat = Meat()
//Tiger().eat(meat)

func isDangerous<T: Animal>(animal: T) -> Bool {
    if animal is Tiger {
        return true
    } else {
        return false
    }
}

isDangerous(animal: Tiger())
isDangerous(animal: Sheep())


